package com.dizang.view.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * 测试请求静态资源
 * Title: IndexController
 * Description: 
 * Company: 
 * @author 蔡俊豪 cocaijunhao
 * @date 2016年9月8日
 *
 */
@Controller
public class IndexController {

	@RequestMapping(value = "/example", method = RequestMethod.GET)
	public ModelAndView example(HttpServletRequest request) {
		return new ModelAndView("/WEB-INF/jsp/index.jsp");
	}
	
	@RequestMapping(value = "/example1", method = RequestMethod.GET)
	public ModelAndView example1(HttpServletRequest request) {
		return new ModelAndView("/index.html");
	}

	@RequestMapping(value = "/example2", method = RequestMethod.GET)
	public ModelAndView example2(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("example3"); //返回的文件名 
		mav.addObject("message","hello kitty"); 
		return mav;
	}
	
	@RequestMapping(value = "/example3", method = RequestMethod.GET)
	public void example3(HttpServletRequest request,HttpServletResponse response) throws IOException {
		String attribute = (String)request.getAttribute("message");
		System.out.println(attribute);
		response.getWriter().write(attribute);
	}
	
	@RequestMapping(value = "/example4", method = RequestMethod.GET)
	public String example4(HttpServletRequest request) {
		return "/index.html";
	}
}